#include <iostream>
#include <vector>

int direction_vec[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

void dfs(std::vector<std::string> war_map,
         std::vector<std::vector<bool>> &vis_map,
         int i, int j, int &num)
{
    if (vis_map[i][j])
        return;

    vis_map[i][j] = true;
    if (war_map[i][j] == '#')
        return;
    if (war_map[i][j] == 'E')
        num++;
    for (int p = 0; p < 4; p++)
    {
        int y = direction_vec[p][0] + i;
        int x = direction_vec[p][1] + j;
        if (y >= 0 && y < vis_map.size() && x >= 0 && x < vis_map[0].size())
        {
            dfs(war_map, vis_map, y, x, num);
        }
    }
}

int main()
{
    int N, M, K;
    std::cin >> N >> M >> K;

    std::vector<std::string> war_map;
    std::vector<std::vector<bool>> vis_map(N, std::vector<bool>(M, false));
    for (int i = 0; i < N; i++)
    {
        std::string st;
        std::cin >> st;
        war_map.push_back(st);
    }

    int cnt = 0;
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < M; j++)
        {
            if (!vis_map[i][j] && war_map[i][j] != '#')
            {
                int num = 0;
                dfs(war_map, vis_map, i, j, num);
                if (num < K)
                {
                    cnt++;
                }
            }
        }
    }

    std::cout << cnt << std::endl;
    return 0;
}